package com.ruoyi.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.Production;
import com.ruoyi.product.service.IProductionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * productionManagementController
 * 
 * @author ruoyi
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/product/production")
public class ProductionController extends BaseController
{
    @Autowired
    private IProductionService productionService;

    /**
     * 查询productionManagement列表
     */
    @PreAuthorize("@ss.hasPermi('product:production:list')")
    @GetMapping("/list")
    public TableDataInfo list(Production production)
    {
        startPage();
        List<Production> list = productionService.selectProductionList(production);
        return getDataTable(list);
    }

    /**
     * 导出productionManagement列表
     */
    @PreAuthorize("@ss.hasPermi('product:production:export')")
    @Log(title = "productionManagement", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Production production)
    {
        List<Production> list = productionService.selectProductionList(production);
        ExcelUtil<Production> util = new ExcelUtil<Production>(Production.class);
        util.exportExcel(response, list, "productionManagement数据");
    }

    /**
     * 获取productionManagement详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:production:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productionService.selectProductionById(id));
    }

    /**
     * 新增productionManagement
     */
    @PreAuthorize("@ss.hasPermi('product:production:add')")
    @Log(title = "productionManagement", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Production production)
    {
        return toAjax(productionService.insertProduction(production));
    }

    /**
     * 修改productionManagement
     */
    @PreAuthorize("@ss.hasPermi('product:production:edit')")
    @Log(title = "productionManagement", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Production production)
    {
        return toAjax(productionService.updateProduction(production));
    }

    /**
     * 删除productionManagement
     */
    @PreAuthorize("@ss.hasPermi('product:production:remove')")
    @Log(title = "productionManagement", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productionService.deleteProductionByIds(ids));
    }
}
